package com.verlet.stringsplit.spring.boot;

import com.verlet.stringsplit.spring.boot.service.StringsplitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动配置类
 *
 * @author verlet
 */
@Configuration
@ConditionalOnClass(StringsplitService.class)
@EnableConfigurationProperties(StringsplitProperties.class)
public class StringsplitAutoConfigure {
    @Autowired
    private StringsplitProperties stringsplitProperties;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "stringsplit.service", value = "enable", havingValue = "true")
    StringsplitService stringsplitService() {
        return new StringsplitService(stringsplitProperties.getConfig());
    }
}
